package com.huqu.basedao;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.SqlParameter;
import org.springframework.jdbc.core.support.JdbcDaoSupport;
import org.springframework.stereotype.Component;

import com.huqu.utils.ApplicationConstant;

/**
 * @author thoai nguyen
 *
 */
public class QbDaoSupport {
	private Object objectReturn;//object return sau khi execute
	private JdbcTemplate jdbcTemplate;
	public QbStoreProcedure queenbStoreProcedure;
	@Autowired
	@Qualifier(value = "qbMySqlExecuteQuery")
	private QbExecuteQuery queenbExcuteQuery;

	@Autowired
	@Qualifier(value = "dataSource")
	public void setDataSource(DataSource dataSource) {
		jdbcTemplate = new JdbcTemplate(dataSource);
		queenbStoreProcedure = new QbStoreProcedure(jdbcTemplate);
	}
	//set tham so truyen  vao 
	public void setQueenBListSqlParams(List<QbSqlParam> listSqlQbParams) {
		queenbStoreProcedure.setListSqlQbParam(listSqlQbParams);
	}
	//set ten proc or function
	public void setQueenBSqlName(String sqlName) {
		queenbStoreProcedure.setSql(sqlName);
	}
	//execute query
	public void executeQueenBQuery() {
		Map<String, Object> mapResult = queenbExcuteQuery.excuteQuery(queenbStoreProcedure);
		objectReturn = mapResult.get(ApplicationConstant.OUT_PARAM_VALUE);
	}
	//set kieu tra ve khi excute function
	public void setQbFunctionReturnType(int type){
		queenbStoreProcedure.setFucitonReturnType(type);
	}
	//set kieu tra ve khi excute procedure
	public void setQueenBEntityMapper(QbEntityMapper entityMapper){
		queenbStoreProcedure.setEntityMapper(entityMapper);
	}
	//lay object ket qua tra ve khi execute procedure
	public List getListReturn() {
		return (List) objectReturn;
	}
	//lay object tra ve khi executefuction
	public Object getObjectReturnFunction(){
		return objectReturn;
	}
	public void setQbFunction(boolean b){
		queenbStoreProcedure.setFunction(b);
	}

}
